package org.carabiner.example;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JPanel;

class ShapeView extends JPanel implements View, PropertyChangeListener
{
  private ShapeModel model;
  
  public ShapeView()
  {
    setPreferredSize(new Dimension(700, 500));
    model = new DefaultShapeModel();
    model.addPropertyChangeListener(this);
  }

  public ShapeModel getShapeModel()
  {
    return model;
  }

  public void propertyChange(PropertyChangeEvent evt)
  {
    Shape shape = (Shape) evt.getNewValue();
    Rectangle bounds = shape.getBounds();
    bounds.grow(1, 1);
    repaint(bounds);    
  }
  
  public void paintComponent(Graphics g)
  {
    super.paintComponent(g);
    model.render((Graphics2D)g);
  }

}
